package org.jks.service;

import java.util.ArrayList;
import java.util.List;

import org.jks.model.FlightAngle;
import org.springframework.stereotype.Service;

@Service
public class FlightAngleService extends EntityService<FlightAngle>{
	
	public FlightAngleService(){
		MODEL_NAME = FlightAngle.class.getSimpleName();
		CLASS_NAME = FlightAngle.class;
	}
	
	public long countByFlightLineId(long id){
		List<Object> params = new ArrayList<Object>();
		params.add(id);
		return count("select count(*) from FlightAngle where FlightLine.Id=?", params);
	}
	
	public List<FlightAngle> findByFlightLineId(long id, int page, int pagesize){
		List<Object> params = new ArrayList<Object>();
		params.add(id);
		return find("from FlightAngle where FlightLine.Id=?", params, page, pagesize);
	}
	
	public List<FlightAngle> searchFlightAngle(FlightAngle fa){
		
		
		String sql = "from FlightAngle";
		String condition = "";
		if(!fa.getIce().equals(""))
		{
			condition += "and Ice like '%" + fa.getIce() + "%'";
		}
		
		if(!fa.getCornerAngle().equals(""))
		{
			condition += "and CornerAngle like '%" + fa.getCornerAngle() +  "%'";
		}
		
		if(!fa.getGroundingType().equals(""))
		{
			condition += "and GroundingType like '%" + fa.getGroundingType() +  "%'";
		}
		
		if(fa.getResistance() != 0)
		{
			condition += "and Resistance=" + fa.getResistance();
		}
		
		if(!condition.equals(""))
		{
			sql += " where Id != 0 " + condition;
		}
		return find(sql);
	}
}
